package com.mystudy.leetcode.problem.link.p_109;

import com.mystudy.leetcode.base.ListNode;

/**
 * @program: infoalgorithm
 * @description: 有序链表转换二叉搜索树
 * @author: zhouzhilong
 * @create: 2019-07-26 17:39
 **/
public class Solution {
    /**
     * 由于需要生成高度平衡的二叉搜索树，所以需要每一个子树都是平衡树
     *
     * @param heap
     * @return
     */
/*
    public TreeNode sortedListToBST(ListNode heap) {
        //先找到中心点作为root
        ListNode rootListNode = getMid(heap);
        TreeNode root = new TreeNode(rootListNode.val);


    }

    private TreeNode sorted(TreeNode node,){

    }
*/






    /**
     * 使用快慢指针法找到中心点
     *
     * @param node
     * @return
     */
    private ListNode getMid(ListNode node) {
        ListNode fast = node;
        ListNode lazy = node;

        while (fast != null) {
            fast = fast.next;
            if (fast != null) {
                fast = fast.next;
            }
            lazy = lazy.next;
        }
        return lazy;
    }
}
